<?php
$name ='fnsoxt';
$pass = 'zzjfish';
$userid = '4940590';
$cookie_jar = ('/tmp/xunlei_cookie');
$options = array(
    CURLOPT_URL => 'http://vip.xunlei.com',
    CURLOPT_COOKIEJAR => $cookie_jar,
    CURLOPT_COOKIEFILE=>$cookie_jar,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => true,
    CURLOPT_FAILONERROR => true,
    CURLOPT_USERAGENT=>'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9',
);

if(file_exists($cookie_jar)) unlink($cookie_jar);
login($name,$pass,$userid,$cookie_jar,$options);
exit;
$time = floor(microtime(true)*1000);
$rt = '0.0'.mt_rand(10000000,99999999).mt_rand(10000000,99999999);
$result = request(array(CURLOPT_URL=>"http://jifen.xunlei.com/call?c=user&a=sign&userid={$userid}&rt={$rt}&callback=jsonp{$time}",CURLOPT_REFERER=>"http://vip.xunlei.com/")+$options);
$data = $result['response'];
$data = ltrim($data,"jsonp{$time}\("); $data = rtrim($data,"\);");
$code = json_decode($data);

$result = request(array(CURLOPT_URL=>"http://jifen.xunlei.com/call?c=user&a=getAllScore&userid={$userid}&rt={$rt}&callback=jsonp{$time}")+$options);
$data = $result['response'];
$data = ltrim($data,"jsonp{$time}\("); $data = rtrim($data,"\);");
$jifen = json_decode($data);

echo date('Y-m-d')."\t".$code->data."\t".$jifen->data."\tdone.\n";

function request($args){
    $ch = curl_init();
    curl_setopt_array($ch, $args);
    $return = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    return array('response' => $return, 'info' => $info);
}

function login($name,$pass,$userid,$cookie_jar,$options){
    $time = floor(microtime(true)*1000);
    $url = "http://vip.xunlei.com/";
    request(array(CURLOPT_URL => $url)+$options);

    $time = floor(microtime(true)*1000);
    $url = "http://login.xunlei.com/check?u={$name}&cachetime={$time}";
    request(array(CURLOPT_URL => $url)+$options);

    $captcha = trim(array_pop(explode(":",array_pop(explode("\t",array_pop(file($cookie_jar)))))));
    $p = md5(md5(md5($pass)).$captcha);
    $time = floor(microtime(true)*1000);
    $request = "http://login.xunlei.com/sec2login?cachetime={$time}";
    $post_data = array('p'=>$p,'u'=>$name,'verifycode'=>$captcha);
   $aa=  request(array(CURLOPT_URL=>$request,CURLOPT_POST => 1,CURLOPT_POSTFIELDS => $post_data)+$options);
    var_dump($aa);
    exit;

    $time = floor(microtime(true)*1000);
    $url = "http://dynamic.vip.xunlei.com/login/asynlogin_contr/asynProxy/?cachetime={$time}&callback=jsonp{$time}";
    request(array(CURLOPT_URL => $url)+$options);

    $time = floor(microtime(true)*1000);
    $url = "http://dyactive.vip.xunlei.com/iface/cash.php?userid={$userid}&outjson=1&cachetime={$time}";
    request(array(CURLOPT_URL => $url)+$options);
}
